package barbershop.com.controller.orders;

import barbershop.com.entity.orders.OrderItem;
import barbershop.com.service.orders.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/orderItem")
public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;

    @RequestMapping("/addAllItems")
    public void addAllItems(@RequestBody List<OrderItem> orderItemList){
        this.orderItemService.updateOrderItem(orderItemList);
    }

    @RequestMapping("/getOrderItemList")
    public List<OrderItem> getOrderItemList(@RequestParam(required = false)Integer orderId){
        return this.orderItemService.getOrderItemList(orderId);
    }

    /** CRUD **/
    @RequestMapping("/add")
    public OrderItem addOrderItem(@RequestBody OrderItem record){
        return this.orderItemService.insert(record);
    }

    @RequestMapping("/delete")
    public Boolean deleteOrderItem(@RequestBody OrderItem record){
        return this.orderItemService.delete(record);
    }

    @RequestMapping("/update")
    public OrderItem updateOrderItem(@RequestBody OrderItem record){ return this.orderItemService.update(record); }

    @RequestMapping("/updateQuantity")
    public void updateQuantity(@RequestParam(required = false)Integer quantity,
                                    @RequestParam(required = false)Integer id){
        this.orderItemService.updateQuantity(quantity, id);
    }

    @RequestMapping("/find")
    public OrderItem findOrderItem(@RequestBody OrderItem record){
        return this.orderItemService.find(record);
    }
}
